package com.example.jacky.android_easeui.demo;

import android.os.Bundle;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ArrayAdapter;
import android.widget.ImageView;

import com.example.jacky.android_easeui.R;
import com.example.jacky.android_easeui.base.BaseActivity;
import com.example.jacky.android_easeui.bean.Cheeses;
import com.example.jacky.uilibrary.view.parallax.MyListView;

/**
 * Created by jacky on 2016/9/30.
 * sounbus app-developer
 * 视差特效
 */

public class ParallaxActivity extends BaseActivity {
    public static final String TAG = "ParallaxActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_parallax);


        final MyListView mListView = (MyListView) findViewById(R.id.lv);
        mListView.setOverScrollMode(View.OVER_SCROLL_NEVER);

        // 加Header
        final View mHeaderView = View.inflate(ParallaxActivity.this, R.layout.view_header, null);
        final ImageView mImage = (ImageView) mHeaderView.findViewById(R.id.iv);
        mListView.addHeaderView(mHeaderView);

        mHeaderView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                // 当布局填充结束之后, 此方法会被调用

                mListView.setParallaxImage(mImage);

                mHeaderView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        });

        // 填充数据
        mListView.setAdapter(new ArrayAdapter<String>(ParallaxActivity.this, android.R.layout.simple_list_item_1, Cheeses.NAMES));

    }
}
